home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
psion
/
pic2ps.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-02
|
4KB
|
161 lines
/*
* Date: Thu, 2 Dec 93 10:48:36 -0800
* From: clive@biosym.com (Clive Freeman)
* Subject: A simple pic to postscript utility
*
*
* This is the source code to a simple
* utility that I wrote to convert psion .pic files to postscript.
*
*/
/*---------------------------------------------------------------------*/
/* Convert PSION s3a simple SCREEN.PIC to .ps, */
/* December 1993, NB. unix box word assumed - L2BW, */
/*---------------------------------------------------------------------*/
#include "stdio.h"
#define TRUE 1
#define FALSE 0
#define L2BW(A) ((A & 0xff00) >> 8) | ((A & 0x00ff) << 8)
#define L2BLW(A) ((L2BW(A & 0x0000ffff) ) << 16 | L2BW((A & 0xffff0000 ) >> 16) )
main(argc,argv)
int argc;
char *argv[];
{
struct p_fsig{
unsigned char id[4];
unsigned char file_ver;
unsigned char app_ver;
unsigned short count;
} signature;
struct ws_pic_header {
unsigned short crc;
unsigned short size[2];
unsigned short byte_size;
unsigned int offset;
} header;
unsigned char *array1, *array2;
int *map;
int i, j, k, l, landscape=FALSE, xinbytes, nbytes;
FILE *fp1, *fp2;
if( argc != 3 && argc != 4 ){ /* Quit because argument count wrong */
printf("usage: pic2ps in.pic out.ps [-l landscape]\n");
exit(1);
}
fp1=fopen( argv[1], "r"); /* Open the files as required by arguments */
if(fp1 == NULL){
printf("File %s cannot be found\n",argv[1]);
printf("usage: pic2ps in.pic out.ps [-l landscape]\n");
exit(1);
}
fp2=fopen( argv[2], "w"); /* Open the files as required by arguments */
if(fp2 == NULL){
printf("File %s cannot be found\n",argv[2]);
printf("usage: pic2ps in.pic out.ps [-l landscape]\n");
exit(1);
}
if ( argc == 4 && strcmp(argv[3], "-l") == 0 )
landscape = TRUE;
fread(&signature, sizeof(signature), 1, fp1);
signature.count = L2BW ( signature.count );
for(i=0; i < signature.count; i++)
fread(&header, sizeof(header), 1, fp1);
if( signature.count != 1 && signature.count != 2){
printf("Warning - Multiple bitmap per file are not supported\n");
}
header.size[0] = L2BW ( header.size[0] );
header.size[1] = L2BW ( header.size[1] );
printf("x %d y %d\n", header.size[0], header.size[1]);
array1 = (unsigned char *) malloc( sizeof(char) * header.size[1] * header.size[0]/8 );
array2 = (unsigned char *) malloc( sizeof(char) * header.size[1] * header.size[0]/8 );
map = (int *) malloc( sizeof (int) * header.size[1] * header.size[0] );
nbytes = header.size[1] * header.size[0] / 8;
fread(array1, nbytes, 1, fp1);
if( signature.count == 2 )
fread(array2, nbytes, 1, fp1);
fclose(fp1);
xinbytes = header.size[0] / 8;
for(j=0;j<header.size[1];j++){
for(i=0;i<xinbytes;i++){
l = 1;
for(k=0; k<8; k++){
if( array1[j*xinbytes+i] & l ){
map[(i*8+k)+header.size[0]*j]=0;
}else{
map[(i*8+k)+header.size[0]*j]=2;
}
if( signature.count == 2 ){
if( array2[j*xinbytes+i] & l ){
if(map[(i*8+k)+header.size[0]*j] != 0)
map[(i*8+k)+header.size[0]*j]=1;
}
}
l *= 2;
}
}
}
fprintf(fp2, "%%!\n");
fprintf(fp2, "initgraphics\n");
fprintf(fp2, "40.000000 45.000000 {dup mul exch dup mul add 1 exch sub} setscreen\n");
fprintf(fp2, "/picstr %d string def\n", header.size[0] );
if(landscape){
fprintf(fp2, "90 rotate\n");
fprintf(fp2, "50 -200.000000 translate\n");
fprintf(fp2, "686.40 -228.80 scale\n");
} else {
fprintf(fp2, "20 730.000000 translate\n");
fprintf(fp2, "451.440009405 -150.480003420 scale\n");
}
fprintf(fp2, "%d %d 8\n", header.size[0], header.size[1] );
fprintf(fp2, "[%d 0 0 %d 0 0]\n",header.size[0], header.size[1]);
fprintf(fp2, "{ currentfile\n");
fprintf(fp2, "picstr readhexstring pop}\n");
fprintf(fp2, "image\n");
for( j=0; j < header.size[1]; j++ ){
for(i=0; i < header.size[0]; i++){
if( map[i+header.size[0]*j] == 0 )
fprintf(fp2, "00");
else if ( map[i+header.size[0]*j] == 1 )
fprintf(fp2, "f0");
else
fprintf(fp2, "ff");
}
fprintf(fp2, "\n");
}
fprintf(fp2, "showpage\n");
fclose(fp2);
free(map);
free(array1);
free(array2);
}